package com.taotao.product.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class FeignInterceptor implements RequestInterceptor {

    @Override
    public void apply(RequestTemplate requestTemplate) {
        if ("post".equalsIgnoreCase(requestTemplate.method()) && requestTemplate.body() == null) {
            String query = requestTemplate.queryLine();
            requestTemplate.queries(new HashMap<>());
            if (query!=null && query.startsWith("?")) {
                requestTemplate.body(query.substring(1));
            }
            requestTemplate.header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        }
    }

}
